<?php

namespace App\Admin\Renderable;

use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;
use App\Models\Vehicle;

class VehicleTable extends LazyRenderable
{
    public function grid(): Grid
    {
        // 获取外部传递的参数
        $id = $this->id;
        $model = Vehicle::with(['series']);
        return Grid::make($model, function (Grid $grid) {
            $grid->column('id');
            $grid->column('series.series_name','车系');
            $grid->column('name','车型');
            $grid->column('code','型号');
            $grid->column('activity_id','绑定的活动ID');

            // 指定行选择器选中时显示的值的字段名称
            // 如果表格数据中带有 “name”、“title”或“phone”字段，则可以不用设置
            $grid->rowSelector()->titleColumn('name');

            $grid->quickSearch(['id', 'name']);

            $grid->paginate(10);
            $grid->disableActions();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id')->width(2);
                $filter->like('name')->width(3);
                $filter->equal('vehicle_series_id')->width(3)->select('api/series');
                $filter->equal('recommend')->select([0 => '否', 1 => '是'])->width(2);
            });
        });
    }
}